{include file="public/header" /}
<body>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item">
                <!-- <div class="layui-inline">
                    <div class="layui-input-inline">
                        <select name="support_type"  lay-search="">
                                <option  value="">不限类型</option>
                            <option  value="1">寺库分期和乐百分分期</option>
                            <option  value="2">寺库分期</option>
                            <option  value="3">乐百分分期</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <div class="layui-input-inline">
                        <select name="group"  lay-search="">
                            <option  value="">不限类型</option>
                            <option  value="3">3期</option>
                            <option  value="6">6期</option>
                            <option  value="12">12期</option>
                            <option  value="24">24期</option>
                        </select>
                    </div>
                </div> -->
                <div class="layui-inline">
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="key" placeholder="输入需查询的标题/名称"/>
                    </div>
                </div>
                <div class="layui-inline">
                    <div class="layui-input-inline">
                        <button class="layui-btn" lay-submit="" lay-filter="LAY-search">立即搜索</button>
                        <button  class="layui-btn layui-btn-normal" id="empty"  lay-submit="" lay-filter="LAY-search">重置</button>
                    </div>
                </div>
            </div>
            <div>
                <button class="layui-btn" data-type="add" onclick="wk.layer_show('添加商家','{:url('Seller/add_config')}')">
                    <i class="fa fa-plus"></i> 添加配置
                </button>
                <span class="layui-btn-dropdown" style="display:inline-block;">
                        <button class="layui-btn layui-btn-danger" data-toggle="dropdown"><i class="fa fa-wrench"></i> 批量操作 <i class="fa fa-caret-down"></i></button>
                        <ul class="layui-dropdown-menu layui-anim layui-anim-upbit">
                            <li><a  href="javascript:;" class="layuiBtn" data-type="excelAll" id="excel"><i class="fa fa-download"></i> 导出Excel</a></li>
                        </ul>
                    </span>
            </div>
        </div>

        <div class="layui-card-body">
            <table id="LAY-table-manage" lay-filter="LAY-table-manage"></table>
            <!--操作模板-->
            <script type="text/html" id="opeBar">
                <a class="layui-btn layui-btn-xs" title="编辑" onclick="wk.layer_show('编辑配置','{:url('edit_config')}?id={{d.id}}')"><i class="fa fa-pencil"></i></a>
                <a class="layui-btn layui-btn-danger layui-btn-xs" title="删除" onclick="wk.confirm('{{d.id}}','{:url('del_config')}')"><i class="fa fa-trash-o"></i></a>
                <a class="layui-btn layui-btn-normal layui-btn-xs" title="生成二维码" lay-submit lay-filter="changeMa" data-value="{{d.id}}" data-url="{{d.url}}"><i class="fa fa-unlink"></i></a>
            </script>
            <!--状态模板-->
            <script type="text/html" id="staBar">
                <input type="checkbox" value="{{d.id}}"  lay-skin="switch"  lay-text="ON|OFF" lay-filter="OnOff"{{ d.status == 1 ? 'checked' : '' }}  >
            </script>
        </div>
    </div>
    <div id="qrcode" style="width:200px;height:200px;"></div>
</div>
{include file="public/footer" /}
<script>
    layui.use(['index', 'table'], function () {
        var $ = layui.$
            , form = layui.form
            , table = layui.table
        table.render({
            elem: '#LAY-table-manage'
            , url: '{:url("Seller/index")}'
            ,response: {
                statusCode: 220 //成功的状态码，默认：0
            }
            , page: true
            , even: false //开启隔行背景
            , size: 'lg' //sm小尺寸的表格 lg大尺寸
            // ,width:100
            , autoSort: false
            , cellMinWidth: 150
            , height: "full-220"
            , limits: [10, 20, 30, 40, 50]
            , limit: "{:config('pages')}"
            , loading: true
            , id: 'LAY-table'
            , cols: [[
                {type: 'checkbox', fixed: 'left',}
                , {field: 'sellor_name', width: '', title: '商家名称', align: 'center'}
                , {field: 'telephone', width: '', title: '商家手机号', align: 'center'}
                , {field: 'username', width: '', title: '业务员姓名', align: 'center'}
                , {field: 'seller_pint', width: '', title: '签约利率', align: 'center'}
                , {field: 's_appid', width: '', title: '寺库商户号', align: 'center'}
                , {field: 's_secret', width: '', title: '寺库商户密钥', align: 'center'}
                , {field: 'l_appid', width: '', title: '乐百分商户号', align: 'center'}
                , {field: 'l_secret', width: '', title: '乐百分商户密钥', align: 'center'}
                , {field: 'type', width: '', title: '签约期数', align: 'center'}
                , {field: 'support_type', title: '支付方式', align: 'center',templet:function(d){
                    if(d.support_type == 1){
                        return '支持寺库分期和乐百分分期'
                    }else if(d.support_type == 2){
                        return '支持寺库分期'
                    }else{
                        return '支持乐百分分期'
                    }
                }}
                , {field: 'create_time', width: '', title: '开通时间', sort: true, align: 'center'}
                , {field: 'status',fixed: 'right', width: 100, title: '状态', align: 'center', templet: '#staBar'}
                , {fixed: 'right', width: 150, title: '操作', align: 'center', toolbar: '#opeBar'}
            ]]
        });
        //监听状态开关操作
        form.on('switch(OnOff)', function (obj) {
            var num = '';
            obj.elem.checked == true? num = 1: num = 0;
            //配置状态
            wk.status(this.value,num, '{:url("status_config")}',obj);
        });
        form.on('submit(changeMa)', function(data){
            // console.log(data.elem.dataset.value)
            var qrcode = new QRCode(document.getElementById("qrcode"), {
                width: 200,
                height: 200,
                colorDark: '#000000',
                colorLight: '#ffffff',
                correctLevel: QRCode.CorrectLevel.H
            });
            var elText = data.elem.dataset.url+data.elem.dataset.value;
            qrcode.makeCode(elText);
            layer.open({
                type: 1,
                title: '商家二维码',
                content: $('#qrcode'), //这里content是一个DOM，注意：最好该元素要存放在body最外层，否则可能被其它的相对元素所影响
                cancel: function(index, layero){
                    document.getElementById("qrcode").innerHTML = '';
                    layer.close(index)
                    return false; 
                }    
            });
        });
        //事件
        var active = {
            getCheckData: function(){
                //批量删除
                wk.batchDel(getIds(),"{:url('batchDelConfig')}");
            }
            ,forbiddenAll: function(){
                //批量禁用
                wk.batchForbidden(getIds(),2,"{:url('forbiddenConfig')}");
            }
            ,excelAll: function(){
                //导出Excel
                wk.excelAll(getIds(),$(".layui-input").serialize(),"{:url('excelAdmin')}");
            }
        };
        $('.layuiBtn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        var getIds = function () {
            var ids = [];
            var checkStatus = table.checkStatus('LAY-table')
                ,data = checkStatus.data;
            $.each(data,function(index,item){
                ids.push(item['id'])
            });
            return ids;
        }
    });
</script>
</body>
</html>